package com.hmall.order.web;

import com.hmall.order.pojo.Order;
import com.hmall.order.service.IOrderService;
import com.hmall.order.web.request.OrderCreateDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

    /**
     * 根据订单id获取订单
     *
     * @param orderId 订单id
     * @return 订单
     */
   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
       log.info("根据订单id获取订单：{}", orderId);
      return orderService.getById(orderId);
   }

    /**
     * 创建订单
     *
     * @param orderCreateDTO 购买数量、付款方式、收货人地址id、商品id
     * @return 订单id
     */
    @PostMapping
    public Long createOrder(@RequestBody OrderCreateDTO orderCreateDTO) {
        log.info("创建订单：{}", orderCreateDTO);
        Long orderId = orderService.createOrder(orderCreateDTO);
        return orderId;
    }
}
